/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
namespace SBJ
{

namespace Arrow
{

inline
Topic::Topic( void )
: m_publication( 0 )
, m_msgProxy( 0 )
, m_shared( 0 )
, m_hash( 0 )
{
}

inline
Topic::Topic( const Topic& rhs )
: m_publication( rhs.m_publication )
, m_msgProxy( rhs.m_msgProxy )
, m_shared( rhs.m_shared )
, m_hash( rhs.m_hash )
{
}

inline
Topic::Topic( const Publication* publication, const MsgProxy* MsgProxy )
: m_publication( publication )
, m_msgProxy( MsgProxy )
, m_shared( 0 )
, m_hash( 0 )
{
}

inline
Topic::Topic( const Publication* publication, SharedData* shared )
: m_publication( publication )
, m_msgProxy( shared->msgProxy )
, m_shared( shared )
, m_hash( shared->hash )
{
}

inline Topic&
Topic::operator = ( const Topic& rhs )
{
	m_publication = rhs.m_publication;
	m_msgProxy = rhs.m_msgProxy;
	m_shared = rhs.m_shared;
	m_hash = rhs.m_hash;
	return *this;
}

inline bool
Topic::isValid( void ) const
{
	return ( m_msgProxy != 0 );
}

inline bool
Topic::isEmpty( void ) const
{
	return ( m_hash == 0 );
}

inline
Topic::operator size_t ( void ) const
{ 
	return m_hash;
}

inline bool
Topic::operator < ( const Topic& rhs ) const
{
	return ( m_hash < rhs.m_hash );
}

inline bool
Topic::operator == ( const Topic& rhs ) const
{
	return ( m_hash == rhs.m_hash );
}

inline const MsgProxy&
Topic::getMsgProxy( void ) const
{
	return *m_msgProxy;
}

inline bool
Topic::isSameMsgType( const Topic& rhs ) const
{
	return ( m_msgProxy == rhs.m_msgProxy );
}

inline const std::string&
Topic::getTopicKey( void ) const
{
	return ( m_shared ? m_shared->key : emptyKey );
}

inline boost::tribool
Topic::hasSubscription( void ) const
{
	return ( m_hash != 0 ? boost::tribool( m_shared->use != 0 ) : boost::indeterminate );
}

inline void
Topic::addUse( void ) const
{
	if ( m_shared ) ++m_shared->use;
}
	
inline void
Topic::removeUse( void ) const
{
	if ( m_shared ) --m_shared->use;
}

}

}